package zy.zy2;

import java.util.ArrayList;
import java.util.Comparator;

public class demo {
    public static void main(String[] args) {
        ArrayList<Dog> dogs = new ArrayList<>();
        dogs.add(new Dog("哈士奇",1,3));
        dogs.add(new Dog("藏獒",2,12));
        dogs.add(new Dog("博美",2,6));
        dogs.add(new Dog("柴犬",3,12));
        dogs.sort(new Comparator<Dog>() {
            @Override
            public int compare(Dog o1, Dog o2) {
                if (o2.age-o1.age>0){
                    return 1;
                }else if (o2.age==o1.age){
                    if (o2.weight-o1.weight>0){
                        return 1;
                    }
                }
                return -1;
            }
        });
        for (Dog d : dogs) {
            System.out.println(d.name+"  "+d.age+"  "+d.weight);
        }
    }
}
